package entities;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * Channel item entity.
 * User: kaiser
 * Date: 7/31/13
 * Time: 9:10 PM
 */


/*
<channels>
   <channel id="habra">Хабрахабр</channe>
   <channel id="ibm-dev">IBM developerWorks</channel>
<channels>
 */
@Entity
@XStreamAlias("channel")
@XStreamConverter(value = ToAttributedValueConverter.class, strings = {"name"})
public class Channel {
    @Id
    @Column(unique = true)

    @XStreamAlias("id")
    @XStreamAsAttribute
    protected String id;

    protected String name;

    @XStreamOmitField
    protected String link;

    public Channel() {

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Channel)) return false;

        Channel channel = (Channel) o;

        if (!id.equals(channel.id)) return false;
        if (!link.equals(channel.link)) return false;
        if (!name.equals(channel.name)) return false;

        return true;
    }

    @Override
    public String toString() {
        return "Channel{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", link='" + link + '\'' +
                '}';
    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + link.hashCode();
        return result;
    }
}
